package org.xjtu.weteam.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.xjtu.weteam.model.domain.Task;
import org.xjtu.weteam.model.dto.StatusNumDTO;
import org.xjtu.weteam.model.dto.TaskDTO;

import java.util.List;

/**
 * @author Kevin
 */

@Mapper
public interface TaskMapper extends BaseMapper<Task> {
    List<Task> taskSearchAll(@Param("projectId") Integer projectId);

    List<TaskDTO> taskSelectAllByUser(@Param("userid") Integer userID, @Param("status") String status);

    List<StatusNumDTO> selectStatusNum(@Param("userid") Integer userID);

    Integer changeTaskStatus(@Param("taskId") Integer taskId, @Param("newStatus") String newStatus);

    List<Task> selectAllParent(@Param("projectid") Integer projectid, @Param("taskId") Integer taskId);
    List<Task> selectAllSon(@Param("projectid") Integer projectid, @Param("taskId") Integer taskId);

    @Insert("INSERT INTO task (`project_id`,`p_id`,`task_name`,`description`,`due_date`,`status`) values (#{projectId}, #{pId},#{taskName},#{description},#{dueDate},#{status})")
    @Options(useGeneratedKeys = true,keyProperty = "taskId")
    void insertTask(Task task);
    @Select("select * from task where task_id = #{id}")
    Task selectByItsId(@Param("id") Integer integer);
    @Update("update task set p_id = #{pId} where task_id = #{taskId}")
    void changeTaskParent(@Param("taskId") Integer taskId,@Param("pId") Integer pId);
    @Select("select * from task where p_id=#{taskId}")
    List<Task> selectSons(@Param("taskId") Integer taskId);
    void updateByItsId(Task task);
}
